package org.hyf.inspur.LessonDesin.clear.count4;

import org.hyf.inspur.LessonDesin.clear.tools.TProperties;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class ProReducer extends Reducer<Text, Text, NullWritable, Text> {
    private Text result = new Text();
    public void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException{
        String promatch = "";
        int flag = 1;
        for (Text val : values) {
            // 判断是否首条数据
            if (flag == 1) {
                promatch = val.toString();
                if (promatch.indexOf("1#") == -1) {
                    return;
                }
                flag = 2;
            } else {
                result = new Text(val.toString()
                        + TProperties.getValue("outfilesplit")
                        + promatch.substring(2)
                        + TProperties.getValue("outfilesplit")
                        + key.toString().split(",")[0]);
                context.write(NullWritable.get(), result);
            }
        }
    }
}

